// 处理资源限时免费下载
import axios from "axios";
import { getAuthToken } from "@/router/index.jsx";

// 获取资源限时免费下载列表
export const activeResourceFreeDownload = (params = {}) => {
  return axios.post("/api/promotion/admin/free-download", {
    headers: {
      Authorization: `Bearer ${getAuthToken()}`,
    },
    params,
  });
};

// 添加限时免费设置API
export const setFreeDownloadApi = (data) => {
  return axios.post('http://192.168.55.192:8080/api/promotion/admin/free-download', data, {
    headers: { Authorization: getAuthToken() }
  }).then(res => res.data);
};

// 获取用户可用折扣券
export const fetchUserDiscountCoupons = () => {
  return axios.get("/api/promotion/user/my-discount-coupons", {
    headers: {
      Authorization: `Bearer ${getAuthToken()}`,
    },
  });
};

// 兑换折扣券
export const exchangeDiscountCoupon = (params = {}) => {
  return axios.post("/api/promotion/exchange-discount", {
    headers: {
      Authorization: `Bearer ${getAuthToken()}`,
    },
    params,
  });
};

// 检测当前是否处于双倍上传奖励时段
export const checkDoubleUploadStatus = () => {
  return axios.get("/api/promotion/double-upload-status", {
    headers: {
      Authorization: `Bearer ${getAuthToken()}`,
    },
  });
};

// 获取当前用户唯独消息列表
export const loadUnreadNotificationsApi = () => {
  return axios.get("/api/user/notifications/unread", {
    headers: {
      Authorization: `Bearer ${getAuthToken()}`,
    },
  });
};

// 标记消息为已读
export const markNotificationReadedApi = (id) => {
  return axios.post(`/api/user/notifications/${id}/read`, {
    headers: {
      Authorization: `Bearer ${getAuthToken()}`,
    },
  });
};

// 回归用户检测
export const returnUserCheckApi = () => {
  return axios.get(`/api/user/return-status`, {
    headers: {
      Authorization: `Bearer ${getAuthToken()}`,
    },
  });
};
